#include<bits/stdc++.h>
using namespace std;

bool checkdate(int n)
{
    int M[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    int year = n/10000;
    int month = n % 10000 /100;
    int day = n % 100;
    if(day <= 0 || month <= 0 || month > 12)
    {
        return false;
    }
    if(month != 2 && day > M[month])
    {
        return false;
    }
    if(month == 2)
    {
        if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
        {
            if(day > 29)
                return false;
        }
        else
        {
            if(day > 28)
                return false;
        }
    }
    return true;
}
bool checkpali(string s)
{
    int len = s.size();
    for(int i = 0, j = len - 1; i < j; i++, j--)
        {
            if(s[i] != s[j])
            {
                return false;
            }
        }
    return true;
}
bool checkABAB(string s)
{
     if(checkpali(s))
     {
         if(s[0] != s[2] || s[1] != s[3] || s[0] == s[1])
         {
             return false;
         }
            else
            {
                 return true;  
             }
      }
    return false;
}
int main()
{
    int flag = 0;
    int n = 0;
    int out1;
    int out2;
    cin >> n;
    for(int i = n + 1;;i++)
    {    
       if(checkdate(i))
       {
          string s = to_string(i);
           if(checkpali(s) && flag == 0)
           {
               cout << i <<endl;
               flag = 1;
               
           }
          if(checkABAB(s))
          {
              cout << i <<endl;
              return 0;
          }
       }
    }
    return 0;
}
